package com.xpxrule.controller.manage;

import com.xpxrule.dataobject.biz.model.ReturnResponse;
import com.xpxrule.dataobject.req.RuleScenariosQueryReq;
import com.xpxrule.dataobject.vo.OptionVo;
import com.xpxrule.dataobject.vo.RuleScenariosVo;
import com.xpxrule.service.RuleScenariosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ruleScenarios")
public class RuleScenariosController {
    @Autowired
    private RuleScenariosService ruleScenariosService;

    /**
     * 新增规则场景
     * @param vo
     * @return
     */
    @PostMapping("/insert")
    public ReturnResponse<Integer> insert(@RequestBody RuleScenariosVo vo) {
        return ruleScenariosService.insert(vo);
    }

    /**
     * 根据id删除规则场景
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ReturnResponse<Integer> delete(@PathVariable("id") Long id) {
        return ruleScenariosService.delete(id);
    }

    /**
     * 根据id更新规则场景
     * @param vo
     * @return
     */
    @PostMapping("/update")
    public ReturnResponse<Integer> update(@RequestBody RuleScenariosVo vo) {
        return ruleScenariosService.update(vo);
    }

    /**
     * 根据查询条件查询规则场景
     * @param req
     * @return
     */
    @PostMapping("/selectList/byQuery")
    public ReturnResponse<List<RuleScenariosVo>> selectList(@RequestBody RuleScenariosQueryReq req) {
        return ruleScenariosService.selectList(req);
    }

    /**
     * 获取所有规则场景下拉选项
     * @return
     */
    @GetMapping("/get/all/ruleScenarios/options")
    public ReturnResponse<List<OptionVo>> getAllRuleScenariosOptions() {
        return ruleScenariosService.getAllRuleScenariosOptions();
    }

    /**
     * 根据规则场景key查询规则场景
     * @param scenariosKey
     * @return
     */
    @GetMapping("/get/ruleScenarios/by/{scenariosKey}")
    public ReturnResponse<RuleScenariosVo> selectRuleScenariosByScenariosKey(@PathVariable("scenariosKey") String scenariosKey) {
        return ruleScenariosService.selectRuleScenariosByScenariosKey(scenariosKey);
    }
}
